//
//  TriggersSettingsModule.m
//  Cantrip
//
//  Created by James Callender on Tue Jun 08 2004.
//  Copyright (c) 2004 James Callender. All rights reserved.
// 

#import "TriggersSettingsModule.h"


@implementation TriggersSettingsModule

- (id)init
{
    if (self = [super init]) {
        [NSBundle loadNibNamed:@"TriggersSettingsView" owner:self];
    }
    
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)awakeFromNib
{
    NSTableColumn *tableColumn = nil;
    CantripImageAndTextCell *imageAndTextCell = nil;
        
    tableColumn = [oOutlineView tableColumnWithIdentifier:@"name"];
    imageAndTextCell = [[[CantripImageAndTextCell alloc] init] autorelease];
    [imageAndTextCell setImage:[NSImage imageNamed:@"ScriptIconSmall"]];
    [imageAndTextCell setEditable: YES];
    [tableColumn setDataCell:imageAndTextCell];

}

- (NSString *)settingsDisplayName
{
    return @"Triggers";
}

- (NSImage *)settingsDisplayIcon
{
    return [NSImage imageNamed:@"Triggers.tiff"];
}

- (NSView *)settingsView
{
    return oSettingsView;
}

- (NSSize)size
{
    return NSMakeSize(589, 335);
}

- (id)world 
{
    return currentWorld;
}

- (void)updateForWorld:(id)world
{
    if (world != currentWorld) {
		[self willChangeValueForKey:@"world"];
		currentWorld = world;
		[self didChangeValueForKey:@"world"];
    }
}

- (NSDictionary *)defaultWorldProperties
{
	return [NSDictionary dictionaryWithObjectsAndKeys:
				[NSMutableArray arrayWithObjects:
					[NSMutableDictionary dictionaryWithObjectsAndKeys:
						[NSNumber numberWithBool:YES], TriggerEnabledKey,
						@"Sample", TriggerNameKey,
					nil],
				nil], @"triggers",
			nil];
}

- (NSArray *)availableVoicesValues
{
    return [NSSpeechSynthesizer availableVoices];
}

- (NSArray *)availableVoices
{
    static NSMutableArray *voices = nil;
    if (voices == nil) {
		NSEnumerator *e; NSString *v;
		voices = [NSMutableArray array];
		e = [[NSSpeechSynthesizer availableVoices] objectEnumerator];
		while (v = [e nextObject]) {
			[voices addObject:[v substringFromIndex:[v rangeOfString:@"." options:NSBackwardsSearch].location + 1]];
		}
    }
    
    return voices;
}	

- (NSMutableDictionary *)triggers
{
	if (currentWorld != nil) return [currentWorld valueForKeyPath:@"data.triggers"];
	return nil;
}

@end
